<?php

namespace app\api\controller;

use app\common\controller\ApiController;
// use app\common\model\Artifacts;

/**
 * artifacts接口
 */
class Artifact extends ApiController
{
    protected $noNeedLogin = ['index'];
    protected $noNeedRight = 'index';
    protected $tableName = 'artifact';
    protected $fields = 'id,name,dynasty,image_url';
    protected $fieldsExcept = false;
    protected $onlySelf = false;
    protected $orderBy = 'id asc';
    protected $conditions = [        
    ];
    protected $defaultPageSize = 30;

    protected function processData($method, $data)
    {
        if ($method === 'beforeIndex') {
            $this->request->param['pageSize'] = 30;
        }
        return $data;
    }
    
    protected function paging()
    {
        $page = $this->request->param('page', 1);
        $pageSize = $this->request->param('pageSize', $this->defaultPageSize ?? 10);
        $pageSize = $pageSize > 100 ? 100 : $pageSize;
        $offset = ($page - 1) * $pageSize;
        return [$offset, $pageSize];
    }
}